package com.example.xianzhi.service.impl;

import com.example.xianzhi.dao.GoodsDao;
import com.example.xianzhi.dao.TypeDao;
import com.example.xianzhi.dao.impl.GoodsDaoImpl;
import com.example.xianzhi.dao.impl.TypeDaoImp;
import com.example.xianzhi.entity.TbGoods;
import com.example.xianzhi.entity.TbType;
import com.example.xianzhi.service.TypeService;

import java.util.List;


public class TypeServiceImpl implements TypeService {
    private TypeDao typeDao = new TypeDaoImp();
    private GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    public List<TbType> selectType() {
        List<TbType> tbTypes = typeDao.selectType();

        for (TbType tbType : tbTypes) {
            List<TbGoods> tbGoods = goodsDao.selectTypeGoods(tbType.getType_id());

            tbType.setGoodslist(tbGoods);

        }
        
        return tbTypes;
    }

    @Override
    public int insertType(String type_name) {
        return typeDao.insertType(type_name);
    }

    @Override
    public int deleteType(int type_id) {
        return typeDao.deleteType(type_id);
    }

    @Override
    public List<TbType> selectType_id(String type_name) {
        return typeDao.selectType_id(type_name);
    }


    @Override
    public List<TbType> selectgoodsuser() {

        List<TbType> tbTypes = typeDao.selectgoodsuser();

        for (TbType tbType : tbTypes) {
            System.out.println(tbType.getType_id());
            List<TbGoods> tbGoods = goodsDao.selecttypeidgoods(tbType.getType_id());
            System.out.println(tbGoods);
            tbType.setGoodslist(tbGoods);

        }

        return tbTypes;
    }
}
